﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data;
using System.Data.SqlClient;
using Models;
using BLL;
using System.Net;
using System.IO;
using System.Text;


namespace Dryricenet
{
    public partial class home_DL : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                this.Page.Form.DefaultButton = "Button1";
            }
        }
            

        //登录
        protected void Button1_Click1(object sender, EventArgs e)
        {
            string name = txtName.Text.Trim();
            string pwd = password.Text.Trim();
            if (name != "" && pwd != "")
            {
                if (userBLL.loginBll(name, pwd).Rows.Count > 0)
                {
                    if (userBLL.sfFHBLL(name, pwd).ToString() == "False")
                    {
                        DataTable dt = userBLL.selectNameBll(name);
                        DataRow dr = dt.Rows[0];//第一条数据
                       int id = Convert.ToInt32(dr["UserID"]);
                        Log l = new Log();
                        l.OperTime = DateTime.Now;
                        l.OperPerson = name;
                        l.Type = "登录系统";
                        l.State = "登录成功";
                        l.ComputerName = Dns.GetHostName().ToUpperInvariant();
                        l.System = Systems.GetOSNameByUserAgent(Environment.OSVersion.ToString());
                        l.UserID = id;
                        LogBLL.LogAddBLL(l);
                        Session["Name"] = name;
                        Session["Pwd"] = pwd;
                        Response.Redirect("home_Center.aspx");
                    }
                    else
                    {
                        Response.Write("<script>javascript:alert('此账号违反干饭网协议！已被封号处理！');history.back();</script>");
                        Response.End();
                    }
                }
                else
                {
                    Response.Write("<script>javascript:alert('亲,登录失败了哦!');history.back();</script>");
                    Response.End();
                   
                }
            }

           
            else if (name == "" && pwd == "")
            {
                Response.Write("<script>javascript:alert('请输入用户名和密码！');</script>");
                Response.End();
            }
        }

        protected void Button2_Click(object sender, EventArgs e)
        {
           

            //if (!CallPhone(txtPhone.Text.ToString()))
            //{
            //    Response.Write("<script>javascript:alert('发送验证码失败！');history.back();</script>");
            //    Response.End();
            //}

        }


    }
}